# Maintainer: Mateusz Mikuła <mati865@gmail.com>

_realname=sqlcipher
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.4.2
pkgrel=1
pkgdesc="SQLite extension that provides transparent 256-bit AES encryption of database files"
arch=('any')
url="https://www.zetetic.net/sqlcipher/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-tcl"
             #"${MINGW_PACKAGE_PREFIX}-sqlite3"
             )
source=("${_realname}-${pkgver}.zip::https://github.com/${_realname}/${_realname}/archive/v${pkgver}.zip"
        "https://www.zetetic.net/$_realname/verify/${pkgver}/${_realname}-${pkgver}.zip.sig"
        "01-fix_dep.diff"
        "02-fix-tcl-find.patch")
validpgpkeys=('D83F5F9EB811D6E6B4A0D9C5D1FA3A2A97ED25C2')   # Zetetic LLC <support@zetetic.net>
sha256sums=('f2afbde554423fd3f8e234d21e91a51b6f6ba7fc4971e73fdf5d388a002f79f1'
            'SKIP'
            'e0cfe85705fd0d7d33b087dfd4cf2f807e1a75f2c9b15f5ceb8b9ff202f6ce5c'
            '048b08a4ddc628111fe9a0f6559e5cf25f0b9414c86109917684115283ab8d6b')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # Debain patch
  patch -p1 -i "${srcdir}"/01-fix_dep.diff

  patch -p1 -i "${srcdir}"/02-fix-tcl-find.patch
  autoreconf -fiv
}

build() {
  cd "${srcdir}"
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir build-${CARCH} && cd build-${CARCH}

  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-tempstore=yes \
    --disable-tcl \
    --disable-editline \
    --enable-readline \
    --with-readline-lib="-L${MINGW_PREFIX}/lib -lreadline" \
    --with-readline-inc="-I${MINGW_PREFIX}/include" \
    CFLAGS="$CFLAGS -DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}"/${_realname}-${pkgver}
  install -Dm644 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
